package com.show.utils;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public class BeanFactory {

    private static Map<String, Object> maps = new HashMap<String, Object>();

    static {
        try {

            ResourceBundle bundle = ResourceBundle.getBundle("bean");

            Enumeration<String> keys = bundle.getKeys();

            while (keys.hasMoreElements()) {
                String key = keys.nextElement();

                String className = bundle.getString(key);

                Class<?> clazz = Class.forName(className);

                Object obj = clazz.newInstance();

                maps.put(key,obj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static <T> T createInstance(String key, Class<T> clazz) {
        return (T) maps.get(key);
    }

/*
    public static <T> T getInstance(String key, Class<T> instance) {
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("bean");
            String className = bundle.getString(key);
            Class<?> aClass = Class.forName(className);
            return (T) aClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }*/


}
